package org.jeecg.modules.wlhy.lnglat.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.modules.wlhy.lnglat.entity.HyShippingnoteLnglat;
import org.jeecg.modules.wlhy.lnglat.mapper.HyShippingnoteLnglatMapper;
import org.jeecg.modules.wlhy.lnglat.service.IHyShippingnoteLnglatService;
import org.jeecg.modules.wlhy.shipping.entity.HyShippingNote;
import org.jeecg.modules.wlhy.shipping.entity.PointDataListVO;
import org.jeecg.modules.wlhy.shipping.entity.WaybillRouteVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: hy_shippingnote_lnglat
 * @Author: jeecg-boot
 * @Date:   2022-04-30
 * @Version: V1.0
 */
@Service
public class HyShippingnoteLnglatServiceImpl extends ServiceImpl<HyShippingnoteLnglatMapper, HyShippingnoteLnglat> implements IHyShippingnoteLnglatService {

    @Autowired
    private IHyShippingnoteLnglatService hyShippingnoteLnglatService;

    @Override
    public WaybillRouteVO getSimulateTrackQuery(HyShippingNote shippingNote) {
        WaybillRouteVO waybillRouteVO = new WaybillRouteVO();
        if (shippingNote == null) {
            return waybillRouteVO;
        }
        List<HyShippingnoteLnglat> gpsDTOS = hyShippingnoteLnglatService.list(new QueryWrapper<HyShippingnoteLnglat>()

                .eq("shipping_num",shippingNote.getShippingNoteNumber()).orderByAsc("create_time"));

        if (gpsDTOS == null) {
            return waybillRouteVO;
        }
        if (CollectionUtils.isNotEmpty(gpsDTOS)) {
            List<PointDataListVO> pointDataListVOs = new ArrayList();
            List<List<String>> valueList = new ArrayList<>();
            for (HyShippingnoteLnglat gpsDTO : gpsDTOS) {
                PointDataListVO pointDataListVO = new PointDataListVO();
                pointDataListVO.setCs(60d);
                pointDataListVO.setLat(gpsDTO.getLatitude().toString());
                pointDataListVO.setLng(gpsDTO.getLongitude().toString());
                pointDataListVO.setReceiveTime(gpsDTO.getCreateTime().toString());
                pointDataListVOs.add(pointDataListVO);

                List<String> valueListString = new ArrayList<>();
                valueListString.add(gpsDTO.getLongitude().toString());
                valueListString.add(gpsDTO.getLatitude().toString());
                valueList.add(valueListString);
            }
            waybillRouteVO.setLineArray(valueList);
            waybillRouteVO.setPointDataList(pointDataListVOs);
        }
        return waybillRouteVO;
    }
}
